<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 学员电访 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-contract"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- 电访记录 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 电访记录 </span>
				<div class="widget-buttons buttons-bordered">
					<button class="btn btn-default btn-sm" title="添加" 
									data-toggle="tooltip" data-placement="top" 
									onclick="handlerAddRow()">
						<i class="fa fa-plus"></i>
					</button>
				</div>
			</div>
			<div class="widget-body editor-body-sm">
				<table data-ajax="handlerSearch" data-method="post" data-toggle="table" 
         			 data-id-field="id" 
							 data-unique-id="id" 
							 data-pagination="true" 
							 data-click-to-select="true" 
							 data-side-pagination="server" 
							 data-mobile-responsive="true" 
							 data-form-search="#search-form-callon" id="table-callon">
					<thead>
						<tr>
							<th data-checkbox="true"></th>
							<th data-field="id" data-visible="false"></th>
							<th data-field="createDate" data-align="center">电访时间</th>
							<th data-field="reason" 		data-align="center" data-formatter="renderReason">状态及原因</th>
							<th data-field="content" 		data-align="center">沟通内容</th>
							<th data-field="length" 		data-align="center">通话时长</th>
							<th data-field="parent"	 		data-align="center">沟通对象</th>
							<th data-field="operator"  	data-align="center" data-formatter="renderOperator" data-table-target="callon">操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
		
		<!-- TODO 家长信息 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 家长信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-parents">
				
			</div>
		</div>
		
		<!-- TODO 学员信息 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 学员信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-student">
				
			</div>
		</div>
		
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-callon" action="/miwawa/{dbname}/common/save" method="post" 
			name="com.app.miwawa.api.eam.entity.StudentCallon">
			<input type="hidden" name="bean['invalid']" value="F">
</form>
<!-- 查询表单 ========================================================= -->
<form id="search-form-student" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Student" 
			data-template-target=".editor-body-student" data-template-id="#view-student-template" 
			data-template-path="/miwawa/content/eam/student/template.html">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="customerId" value="0" data-search-group="and" data-search-operation="EQ">
</form>
<form id="search-form-parents" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Parents" 
			data-template-target=".editor-body-parents" data-template-id="#view-parents-template" 
			data-template-path="/miwawa/content/eam/student/template.html">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="customerId" value="0" data-search-group="and" data-search-operation="EQ">
</form>
<form id="search-form-callon" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.eam.entity.StudentCallon">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="studentId" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" data-search-sort="createDate" data-search-order="desc">
</form>
    
<script type="text/javascript">
<!--
	require(['domReady'],function(domReady){
		domReady(function () {
			loadStudent();
		});
	});
	
	// 加载学员信息
	var contract
	function loadStudent(){
		contract = jQuery("#table-contract").data("selectedRow");
		
		jQuery(":hidden[name='studentId']").val(contract.studentid);
		jQuery(":hidden[name='customerId']").val(contract.customerid);
		
		jQuery("#search-form-student").loadform("many");

		jQuery("#search-form-parents").loadform("many");
		
		jQuery("#table-callon").bootstrapTable({
			onLoadSuccess:function(data){
				require(['jquery.plugin.form'],function(form){
					form.tooltip("[data-toggle='tooltip']");
				});
			}
		});
	}
	
	function renderReason(value, row, index){
		return row.status+" "+value;
	}
	
	// 打开电访记录模态窗口
	function handlerAddRow(){
		jQuery("#extension-modal").data("url","content/eam/student/dialog/callon.html").data("onshow",function(){
			require(['jquery.plugin.form'], function(form){
				jQuery("#parents").empty();
				form.datepicker(jQuery("#createDate",".form-editor-callon"),{format:'YYYY-MM-DD HH:mm'});
				form.chosen("#status").select("#status");
				form.chosen("#parents").select("#parents",{querys:{"customerId_EQ":contract.customerid}},function(chosen){
					jQuery("#mobile",".form-editor-callon").val(contract.parent+":"+contract.mobile);
					jQuery("#parent",".form-editor-callon").val(contract.relation);
					jQuery("#student",".form-editor-callon").val(contract.student);
					jQuery("#studentId",".form-editor-callon").val(contract.studentid);
					
					jQuery("#userid",".form-editor-callon").val(userid);
					jQuery("#username",".form-editor-callon").val(username);
					
					chosen.change(function(event, value){
						var selected = jQuery("#parents > option[value='"+value.selected+"']",".form-editor-callon");
						var parent = selected.data();
						jQuery("#parent",".form-editor-callon").val(selected.text());
						jQuery("#mobile",".form-editor-callon").val(parent.name+":"+parent.mobile);
					});
				});
			});
		}).data("onhidden",function(){
			jQuery("#table-callon").bootstrapTable("refresh");
		}).modal("show");
	}
//-->
</script>